package ru.aslanov.schedule.model;

import javax.jdo.annotations.*;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Created by IntelliJ IDEA.
 * Created: Nov 25, 2009 5:50:25 PM
 *
 * @author Sergey Aslanov
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Teacher extends Entity {
    @Persistent
    private String id;
    @Persistent
    @Embedded(members = {@Persistent(name="dbValue", columns=@Column(name="name"))})
    private I18nString name = new I18nString();
    @Persistent
    @Embedded(members = {@Persistent(name="dbValue", columns=@Column(name="url"))})
    private I18nString url = new I18nString();
    @Persistent
    private String email;

    @Persistent
    private Schedule schedule;    

    public Teacher() {
    }

    public Teacher(String id, String name, String url) {
        this.id = id;
        this.setName(name);
        this.setUrl(url);
    }

    @XmlID
    @XmlAttribute
    public String getId() {
        return id != null ? id : getLocalId();
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlAttribute
    public String getName() {
        return name.getValueWithThreadLang();
    }

    public void setName(String name) {
        this.name.setValueWithThreadLang(name);
    }

    @XmlAttribute
    public String getUrl() {
        return url.getValueWithThreadLang();
    }

    public void setUrl(String url) {
        this.url.setValueWithThreadLang(url);
    }

    @XmlAttribute
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email != null ? email.toLowerCase() : null;
    }

    @XmlTransient
    public Schedule getSchedule() {
        return schedule;
    }

    public void setSchedule(Schedule schedule) {
        this.schedule = schedule;
    }

    @Override
    public String toString() {
        return getName();
    }

}
